<?php
require_once "config.php";
$adv="createpoll.php";
if (isset($_POST['add'])){
setcookie("ansvnum", $_POST['ansvnum'], time() + 360000);
setcookie("pollname", $_POST['title'], time() + 360000);
for ($i = 1; $i <= $_POST["ansvs"]; $i++) {
setcookie("ansv".$i."", $_POST["ansv".$i.""], time() + 360000);
}
echo "<html><head><meta  http-equiv='refresh' content='0; url=".$adv."' ></head></html>";
}

if (isset($_POST['send'])){
$pollname = $_POST['title'];
$url ="url";
$type = "single";
$query = "INSERT INTO polls (`pollname`, `url`, `type`) 
			VALUES ('$pollname', '$url', '$type')";
			$res = mysql_query($query);
for ($i = 1; $i <= $_POST["ansvs"]; $i++) {
If ($_POST["ansv".$i.""]!==""){
$text = $_POST["ansv".$i.""];
$query = "INSERT INTO pollansv (`pollurl`, `text`, `col`) 
			VALUES ('$url', '$text', '0')";
			$res = mysql_query($query);
}
}
setcookie("ansvnum", "", time() - 3600);
setcookie("pollname", "", time() - 3600);
setcookie("ansvnum", "", time() - 3600);
for ($i = 1; $i <= $_POST["ansvs"]; $i++) {
setcookie("ansv".$i."", "", time() - 3600);
}
echo "<html><head><meta  http-equiv='refresh' content='0; url=".$adv."' ></head></html>";
}
if (!isset($_COOKIE["ansvnum"])){ 
setcookie("ansvnum", 5);
echo "<html><head><meta  http-equiv='refresh' content='0; url=".$adv."' ></head></html>";
}
else{
echo '<form action = "createpoll.php" method="post">';
echo '<label for="title">Название: </label>';
echo '<input id="title" name="title" type="text" maxlength="255" value = "';
if (isset($_COOKIE["pollname"])) echo $_COOKIE["pollname"];
echo '"/><br />';
for ($i = 1; $i <= $_COOKIE["ansvnum"]; $i++) {
echo '<input id="ansv'.$i.'" name="ansv'.$i.'" type="text" maxlength="255" value = "';
if (isset($_COOKIE["ansv".$i.""])) echo $_COOKIE["ansv".$i.""];
echo '"/><br />';
}
echo '<input id="ansvnum" name="ansvnum" type="text" maxlength="255" value = "';
if (isset($_COOKIE["ansvnum"])) echo $_COOKIE["ansvnum"];
echo '"/><br />';
echo '<input id="ansvs" name="ansvs" type="hidden" value="'.$_COOKIE["ansvnum"].'" />';
echo '<input type = "submit" name = "add" value = "+" />';
echo '<input type = "submit" name = "send" value = "Отправить" />';
echo '</form>';
}



?>

